//
// Created by Administrator on 2021/6/13.
//

#include <bits/stdc++.h>
using namespace std;

struct instruction{
    string f;
    int l,a;
    instruction(){
    }
    instruction(string F, int L, int A){
        f = F;
        l = L;
        a = A;
    }
};
vector<instruction> code;
vector<int> Stack;
int IP = 0,BP = 0,SP = -1;

void writeBuffer(){
    SP++;
    while (SP >= Stack.size()) Stack.push_back(0);
}
int getAndPop(){
    return Stack[SP--];
}

void runInstruction(){
    instruction nowIR(code[IP].f,code[IP].l,code[IP].a);
    if (nowIR.f == "LIT"){
        writeBuffer();
        Stack[SP] = nowIR.a;
    }
    else if (nowIR.f == "LOD"){
        int point = BP;
        while (nowIR.l){
            point = Stack[point];
            nowIR.l --;
        }
        writeBuffer();
        Stack[SP] = Stack[point+nowIR.a];
    }
    else if (nowIR.f == "STO"){
        int point = BP;
        while (nowIR.l){
            point = Stack[point];
            nowIR.l --;
        }
        int top = getAndPop();
        Stack[point+nowIR.a] = top;
    }
    else if (nowIR.f == "CAL"){
        int point = BP;
        while (nowIR.l){
            point = Stack[point];
            nowIR.l --;
        }
        writeBuffer();
        Stack[SP] = point;
        writeBuffer();
        Stack[SP] = BP;
        writeBuffer();
        Stack[SP] = IP;
        SP -= 3;
        BP = SP +1;
        IP = nowIR.a - 1;
    }
    else if (nowIR.f == "INT"){
        SP += nowIR.a;
    }
    else if (nowIR.f == "JMP"){
        IP = nowIR.a - 1;
    }
    else if (nowIR.f == "JPC" && Stack[SP--] == 0){
        IP = nowIR.a - 1;
    }
    else if (nowIR.f == "OPR"){
        switch (nowIR.a) {
            case 0:{
                SP = BP - 1;
                IP = Stack[SP + 3];
                BP = Stack[SP + 2];
                if (!IP){
                    IP = -1;
                }
                break;
            }
            case 1:{
                Stack[SP] %= 2;
                break;
            }
            case 2:{
                int top = Stack[SP--];
                Stack[SP] = int(Stack[SP] == top);
                break;
            }
            case 3:{
                int top = Stack[SP--];
                Stack[SP] = int(Stack[SP] != top);
                break;
            }
            case 4:{
                int top = Stack[SP--];
                Stack[SP] = int(Stack[SP] < top);
                break;
            }
            case 5:{
                int top = Stack[SP--];
                Stack[SP] = int(Stack[SP] <= top);
                break;
            }
            case 6:{
                int top = Stack[SP--];
                Stack[SP] = int(Stack[SP] > top);
                break;
            }
            case 7:{
                int top = Stack[SP--];
                Stack[SP] = int(Stack[SP] >= top);
                break;
            }
            case 8:{
                Stack[SP] = -Stack[SP];
                break;
            }
            case 9:{
                int top = Stack[SP--];
                Stack[SP] += top;
                break;
            }
            case 10:{
                int top = Stack[SP--];
                Stack[SP] -= top;
                break;
            }
            case 11:{
                int top = Stack[SP--];
                Stack[SP] *= top;
                break;
            }
            case 12:{
                int top = Stack[SP--];
                Stack[SP] /= top;
                break;
            }
            case 13:{
                int x;
                cin >> x;
                SP++;
                while (SP >= Stack.size()) Stack.push_back(0);
                Stack[SP] = x;
                break;
            }
            case 14:{
                int top = Stack[SP--];
                cout << top <<endl;
                break;
            }
        }
    }
    IP++;
}


int main(){
    ifstream file;
    file.open("program.code");
    instruction x;
    while (file >> x.f >> x.l >> x.a){
        code.push_back(x);
    }

    for (int i = 1;i<=3;i++){
        Stack.push_back(0); // push SL DL RA
    }
    while (1){
        runInstruction();
        if (IP == 0) return 0;
    }

}